<template>
  <el-dialog title="修改新闻"
             :visible.sync="visible"
             @close="handleCancelEdit">
    <el-form ref="UpdateDataForm" :model="updateTemp" >
      <el-form-item label="发布时间" prop="">
        <!--<el-input v-model="updateTemp.publishedAt" type="text">-->
        <!--</el-input>-->
        <el-date-picker
          v-model="updateTemp.publishedAt"
          type="datetime"
          format="yyyy-MM-dd HH:mm"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="标题" prop="">
        <el-input v-model="updateTemp.title" type="text" >
        </el-input>
      </el-form-item>
      <el-form-item >
        <p>上传图片</p>
        <el-upload
          action="/api/v1/uploads"
          list-type="picture-card"
          class="upload__container"
          :on-success="uploadSucess"
          :limit="1"
        >
          <i class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible" :append-to-body="true">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
      </el-form-item>
      <el-form-item label="作者" prop="">
        <el-input v-model="updateTemp.author" type="text" >
        </el-input>
      </el-form-item>
      <el-form-item label="描述" prop="">
        <el-input v-model="updateTemp.description" type="text" >
        </el-input>
      </el-form-item>
      <div class="editor-container">
        <tinymce :height=400
                 ref="editor"
                 :init="initContent"
                 v-model="updateTemp.content"
                 ></tinymce>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancelEdit">取消</el-button>
      <el-button type="primary" @click="handleUpdateData">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import Tinymce from '@/components/Tinymce'

  export default {
    name: 'update-dialog',
    components: {
      Tinymce
    },
    data() {
      return {
        visible: false,
        ileList: [],
        dialogImageUrl: '',
        dialogVisible: false,
        img_id: null
      }
    },
    props: {
      updateTemp: Object,
      dialogUpdateFormVisible: Boolean,
      initContent: Boolean
    },
    watch: {
      dialogUpdateFormVisible(val) {
        this.visible = val
      }
    },
    methods: {
      handleCancelEdit() {
        this.visible = false
        this.$emit('cancel', this.visible)
      },
      handleUpdateData() {
        this.$emit('update', this.img_id)
      },
      uploadSucess(res) {
        this.img_id = res.data.asset.id
      }
    }
  }
</script>

<style scoped>

</style>
